﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="BillFilter.cs" company="Concept Architecture">
//   (c) 2010 Muhammad Umer Farooq
// </copyright>
// <summary>
//   Defines the <seealso cref="Hisaab.Data.Filters.BillFilter" /> type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Hisaab.Data.Filters
{
    using System;
    using System.Data.Objects;
    using System.Linq;
    using Entities;

    /// <summary>
    /// Defines the <seealso cref="Hisaab.Data.Filters.BillFilter"/> type.
    /// </summary>
    public static class BillFilter
    {
        /// <summary>
        /// Filters the specified Bill tags.
        /// </summary>
        /// <param name="collection">The bills.</param>
        /// <param name="objectToMatch">The bill to match.</param>
        /// <returns>List of filtered Bills</returns>
        public static IQueryable<Bill> Filter(this IObjectSet<Bill> collection, Bill objectToMatch)
        {
            return objectToMatch == null ?
                collection :
                from target in collection
                where (objectToMatch.Id == 0 || target.Id == objectToMatch.Id) &&
                (objectToMatch.Name == null || target.Name.Equals(objectToMatch.Name, StringComparison.InvariantCultureIgnoreCase)) &&
                (!objectToMatch.DueDate.HasValue || target.DueDate == objectToMatch.DueDate) &&
                (!objectToMatch.ExpiryDate.HasValue || target.ExpiryDate == objectToMatch.ExpiryDate) &&
                (!objectToMatch.Paid.HasValue || target.Paid == objectToMatch.Paid) &&
                (!objectToMatch.Recurring.HasValue || target.Recurring == objectToMatch.Recurring) &&
                (!objectToMatch.RecurringFequency.HasValue || target.RecurringFequency == objectToMatch.RecurringFequency)
                select target;
        }
    }
}